package cn.itcast.utils;

import cn.itcast.dao.StudentDao;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MyUtils {
    private MyUtils() {
    }

    /**
     *
     * @param
     * @return StudentDao
     */
    public static StudentDao getStudentDao(){
        try {
            InputStream is = Resources.getResourceAsStream("mybatis-config.xml");
            SqlSession sqlSession = new SqlSessionFactoryBuilder().build(is).openSession(true);
            StudentDao studentDao = sqlSession.getMapper(StudentDao.class);
            return studentDao;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
}
